package controler;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import pojo.Person;
import service.PersonDaoManager;

@Controller
public class PersonRegistControler {
	@Autowired
	@Qualifier(value="personDaoManager")
	private PersonDaoManager personManager;
	
	@ResponseBody
	@RequestMapping(value="/addPerson",consumes="application/json",method=RequestMethod.POST)
	public Person addPerson(@RequestBody Person person){
		Person personPutBack = personManager.addPerson(person);
		return personPutBack;
	}
	
	@ResponseBody
	@RequestMapping(value="/deletePerson",consumes="application/json",method=RequestMethod.DELETE)
	public int deletePerson(String id){
		System.out.println(id);
		return personManager.deletePerson(id);
	}
	 
	@ResponseBody
	@RequestMapping(value="/updatePerson",consumes="application/json",method=RequestMethod.PUT)
	public Person updatePerson(@RequestBody Person person){
		return personManager.updatePerson(person);
	}
	
	@ResponseBody
	@RequestMapping(value="/findAllPerson",consumes="application/json",method=RequestMethod.GET)
	public List<Person> findAllPerson(){
		return  personManager.findAllPerson();
	}
}
